package com.jhgsys.internal.hazard.controller;

import com.jhgsys.internal.common.annotation.Log;
import com.jhgsys.internal.common.controller.BaseController;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.entity.FebsResponse;
import com.jhgsys.internal.common.entity.QueryRequest;
import com.jhgsys.internal.common.entity.FebsConstant;
import com.jhgsys.internal.common.exception.FebsException;
import com.jhgsys.internal.common.utils.FebsUtil;
import com.jhgsys.internal.hazard.entity.HazardExamineDtlConfig;
import com.jhgsys.internal.hazard.service.IHazardExamineDtlConfigService;
import com.wuwenze.poi.ExcelKit;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
import javax.validation.constraints.NotBlank;
import java.util.Date;

/**
 *  Controller
 *
 * @author Lujiachen
 * @date 2024-08-13 08:57:26
 */
@Slf4j
@Validated
@Controller
public class HazardExamineDtlConfigController extends BaseController {

    @Autowired
    private IHazardExamineDtlConfigService hazardExamineDtlConfigService;

    @GetMapping(FebsConstant.VIEW_PREFIX + "hazardExamineDtlConfig")
    @RequiresPermissions("hazardExamineDtlConfig:view")
    public String hazardExamineDtlConfigIndex(){
        return FebsUtil.view("hazard/hazardExamineDtlConfig/hazardExamineDtlConfigList");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "hazardExamineDtlConfig/add")
    @RequiresPermissions("hazardExamineDtlConfig:add")
    public String hazardExamineDtlConfigAdd(){
        return FebsUtil.view("hazard/hazardExamineDtlConfig/hazardExamineDtlConfigEdit");
    }

    @GetMapping(FebsConstant.VIEW_PREFIX + "hazardExamineDtlConfig/update/{id}")
    @RequiresPermissions("hazardExamineDtlConfig:edit")
    public String hazardExamineDtlConfigUpdate(Model model, @PathVariable("id") String id){
        model.addAttribute("hazardExamineDtlConfig", hazardExamineDtlConfigService.findHazardExamineDtlConfigById(id));
        return FebsUtil.view("hazard/hazardExamineDtlConfig/hazardExamineDtlConfigEdit");
    }

    /**
     * 查询（所有）
     * @author Lujiachen
     * @date 2024-08-13 08:57:26
     */
    @GetMapping("hazardExamineDtlConfig")
    @ResponseBody
    @RequiresPermissions("hazardExamineDtlConfig:view")
    public FebsResponse getAllHazardExamineDtlConfigs(HazardExamineDtlConfig hazardExamineDtlConfig) {
        return new FebsResponse().success().data(hazardExamineDtlConfigService.findHazardExamineDtlConfigList(hazardExamineDtlConfig));
    }

    /**
     * 查询（分页）
     * @author Lujiachen
     * @date 2024-08-13 08:57:26
     */
    @GetMapping("hazardExamineDtlConfig/list")
    @ResponseBody
    @RequiresPermissions("hazardExamineDtlConfig:view")
    public FebsResponse hazardExamineDtlConfigList(QueryRequest request, HazardExamineDtlConfig hazardExamineDtlConfig) {
        Map<String, Object> dataTable = getDataTable(this.hazardExamineDtlConfigService.findHazardExamineDtlConfigPage(request, hazardExamineDtlConfig));
        return new FebsResponse().success().data(dataTable);
    }

    /**
     * 新增 HazardExamineDtlConfig
     * @author Lujiachen
     * @date 2024-08-13 08:57:26
     */
    @Log("新增HazardExamineDtlConfig")
    @PostMapping("hazardExamineDtlConfig")
    @ResponseBody
    @RequiresPermissions("hazardExamineDtlConfig:add")
    public FebsResponse addHazardExamineDtlConfig(@Valid HazardExamineDtlConfig hazardExamineDtlConfig) throws FebsException {
        try {
            hazardExamineDtlConfig.setCreatedBy(getCurrentUser().getUserName());
            this.hazardExamineDtlConfigService.createHazardExamineDtlConfig(hazardExamineDtlConfig);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "新增HazardExamineDtlConfig失败";
            log.error(message, e);
            return failure(e,message);
        }
    }

    /**
     * 逻辑删除 HazardExamineDtlConfig
     * @author Lujiachen
     * @date 2024-08-13 08:57:26
     */
    @Log("逻辑删除HazardExamineDtlConfig")
    @GetMapping("hazardExamineDtlConfig/delete/{id}")
    @ResponseBody
    @RequiresPermissions("hazardExamineDtlConfig:delete")
    public FebsResponse deleteHazardExamineDtlConfig(@PathVariable("id") String hazardExamineDtlConfigIds) throws FebsException {
        try {
            HazardExamineDtlConfig hazardExamineDtlConfig = new HazardExamineDtlConfig();
            hazardExamineDtlConfig.setDeletedBy(getCurrentUser().getUserName());
            hazardExamineDtlConfig.setDeletedTime(new Date());
            hazardExamineDtlConfig.setDeletedFlg(FebsConstant.INVALID);
            this.hazardExamineDtlConfigService.deleteHazardExamineDtlConfig(hazardExamineDtlConfig,hazardExamineDtlConfigIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除HazardExamineDtlConfig失败";
            log.error(message, e);
            return failure(e,message);
        }
    }

    /**
    * 物理删除 HazardExamineDtlConfig
    * @author Lujiachen
    * @date 2024-08-13 08:57:26
    */
    @Log("物理删除HazardExamineDtlConfig")
    @GetMapping("hazardExamineDtlConfig/physicallyDelete/{id}")
    @ResponseBody
    @RequiresPermissions("hazardExamineDtlConfig:delete")
    public FebsResponse physicallyDeleteHazardExamineDtlConfig(@PathVariable("id") String hazardExamineDtlConfigIds) throws FebsException {
        try {
            this.hazardExamineDtlConfigService.physicallyDeleteHazardExamineDtlConfig(hazardExamineDtlConfigIds);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "删除HazardExamineDtlConfig失败";
            log.error(message, e);
            return failure(e,message);
        }
    }

    /**
     * 修改 HazardExamineDtlConfig
     * @author Lujiachen
     * @date 2024-08-13 08:57:26
     */
    @Log("修改HazardExamineDtlConfig")
    @PostMapping("hazardExamineDtlConfig/update")
    @ResponseBody
    @RequiresPermissions("hazardExamineDtlConfig:edit")
    public FebsResponse updateHazardExamineDtlConfig(HazardExamineDtlConfig hazardExamineDtlConfig) throws FebsException {
        try {
            hazardExamineDtlConfig.setUpdatedBy(getCurrentUser().getUserName());
            this.hazardExamineDtlConfigService.updateHazardExamineDtlConfig(hazardExamineDtlConfig);
            return new FebsResponse().success();
        } catch (Exception e) {
            String message = "修改HazardExamineDtlConfig失败";
            log.error(message, e);
            return failure(e,message);
        }
    }

}
